<?php
/* Created by Chee Hwa
|	Categories include: Open Shelf Books, Novels, Lifestyle Books, Featured Films, Music, New Arrivals
*/
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class spinme extends CI_Controller {
	public function retrieveItems() {
		$category = $_POST['category'];
		$map_openShelfBooks_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=wcl=os'; 
		$map_novels_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=wcl=fic'; 
		$map_lifestyleBooks_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=wcl=lf'; 
		$map_featuredFilms_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=((WCL=DVD or WCL=VCD or WCL=SDVD) AND (WFM=VM) AND (WIS=19 or WIS=01))';
		$map_music_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=wcl=MCD L';
		$map_newArrivals_url = 'http://libcat.tp.edu.sg/X?op=find&base=tpl01&request=wnt=nt';		
		$response_xml_data;
		
		switch($category) {
			case 'openShelfbooks':
				$response_xml_data = simplexml_load_file($map_openShelfBooks_url);
				break;
			case 'novels':
				$response_xml_data = simplexml_load_file($map_novels_url);
				break;
			case 'lifestyleBooks':
				$response_xml_data = simplexml_load_file($map_lifestyleBooks_url);
				break;
			case 'featureFilms':
				$response_xml_data = simplexml_load_file($map_featuredFilms_url);
				break;
			case 'music':
				$response_xml_data = simplexml_load_file($map_music_url);
				break;
			case 'newArrivals':
				$response_xml_data = simplexml_load_file($map_newArrivals_url);
				break;
		}
		$number1 = rand(1,(int) $response_xml_data->set_number);
		$number2 = $number1; $number3 = $number1; $number4 = $number1; $number5 = $number1;
		// $number2 = rand(1,$response_xml_data->set_number);
		// while ($number2 == $number1) {
			// $number2 = rand(1,$response_xml_data->set_number);
		// }

		
		echo $number1;
		return $response_xml_data;
	}
	
}

?>